﻿Imports DotNetNuke.Common.Utilities.DataCache
Imports DotNetNuke.Entities.Modules

Namespace RTP.RTPTooltip

#Region "RTPTooltipSettings"
    Public Class RTPTooltipSettings
#Region "Private Members"
        Private _allsettings As Hashtable
        Private _moduleID As Integer = -1

        Private _RTPTooltipClientIDs As String()
        Private _AutoTooltipify As Boolean = False
        Private _RelativeTo As Telerik.Web.UI.ToolTipRelativeDisplay = Telerik.Web.UI.ToolTipRelativeDisplay.Mouse
        Private _HideEvent As Telerik.Web.UI.ToolTipHideEvent = Telerik.Web.UI.ToolTipHideEvent.Default
        Private _EnableShadow As Boolean = False

#End Region

#Region " Constructors "
        Public Sub New()
        End Sub

        Public Sub New(ByVal ModuleId As Integer)
            _moduleID = ModuleId
            Dim mc As New ModuleController
            _allsettings = mc.GetModuleSettings(_moduleID)

            ReadValue(_allsettings, "RTPTooltipClientIDs", RTPTooltipClientIDs)
            ReadValue(_allsettings, "AutoTooltipify", AutoTooltipify)
            ReadValue(_allsettings, "RelativeTo", RelativeTo)
            ReadValue(_allsettings, "HideEvent", HideEvent)
            ReadValue(_allsettings, "EnableShadow", EnableShadow)

        End Sub
#End Region

#Region " Public Methods "

        Public Sub SaveSettings(ByVal ModuleId As Integer)

            Dim objModules As New ModuleController
            With objModules
                Dim RTPBase As New RTPTooltipBase
                .UpdateModuleSetting(ModuleId, "RTPTooltipClientIDs", RTPBase.ArrayToString(Me.RTPTooltipClientIDs))
                .UpdateModuleSetting(ModuleId, "AutoTooltipify", Me.AutoTooltipify.ToString)
                .UpdateModuleSetting(ModuleId, "RelativeTo", CInt(Me.RelativeTo).ToString)
                .UpdateModuleSetting(ModuleId, "HideEvent", CInt(Me.HideEvent).ToString)
                .UpdateModuleSetting(ModuleId, "EnableShadow", Me.EnableShadow.ToString)
            End With
            Dim CacheKey As String = "RTPTooltipSettings" & ModuleId.ToString
            SetCache(CacheKey, Me)

        End Sub

        Public Function GetRTPTooltipSettings(ByVal ModuleID As Integer) As RTPTooltipSettings
            _moduleID = ModuleID
            If _moduleID > 0 Then
                Dim CacheKey As String = "RTPTooltipSettings" & ModuleID.ToString
                Dim bs As RTPTooltipSettings = Nothing
                bs = CType(GetCache(CacheKey), RTPTooltipSettings)
                If bs Is Nothing Then
                    bs = New RTPTooltipSettings(_moduleID)
                    SetCache(CacheKey, bs)
                End If
                Return bs
            End If
            Return Nothing
        End Function

#End Region


#Region "Public Properties "
        Public Property HideEvent() As Telerik.Web.UI.ToolTipHideEvent
            Get
                Return _HideEvent
            End Get
            Set(ByVal Value As Telerik.Web.UI.ToolTipHideEvent)
                _HideEvent = Value
            End Set
        End Property

        Public Property RelativeTo() As Telerik.Web.UI.ToolTipRelativeDisplay
            Get
                Return _RelativeTo
            End Get
            Set(ByVal Value As Telerik.Web.UI.ToolTipRelativeDisplay)
                _RelativeTo = Value
            End Set
        End Property

        Public Property AutoTooltipify() As Boolean
            Get
                Return _AutoTooltipify
            End Get
            Set(ByVal Value As Boolean)
                _AutoTooltipify = Value
            End Set
        End Property

        Public Property EnableShadow() As Boolean
            Get
                Return _EnableShadow
            End Get
            Set(ByVal Value As Boolean)
                _EnableShadow = Value
            End Set
        End Property

        Public Property RTPTooltipClientIDs() As String()
            Get
                Return _RTPTooltipClientIDs
            End Get
            Set(ByVal Value As String())
                _RTPTooltipClientIDs = Value
            End Set
        End Property
#End Region

#Region " Private Methods "

        Private Shared Sub ReadValue(ByRef ValueTable As Hashtable, ByVal ValueName As String, ByRef Variable As String)
            If Not ValueTable.Item(ValueName) Is Nothing Then
                Try
                    Variable = CType(ValueTable.Item(ValueName), String)
                Catch ex As Exception
                End Try
            End If
        End Sub

        Private Shared Sub ReadValue(ByRef ValueTable As Hashtable, ByVal ValueName As String, ByRef Variable As String())
            If Not ValueTable.Item(ValueName) Is Nothing Then
                Try
                    Dim RTPBase As New RTPTooltipBase
                    Variable = RTPBase.StringToArray(CType(ValueTable.Item(ValueName), String))
                Catch ex As Exception
                End Try
            End If
        End Sub

        Private Shared Sub ReadValue(ByRef ValueTable As Hashtable, ByVal ValueName As String, ByRef Variable As Integer)
            If Not ValueTable.Item(ValueName) Is Nothing Then
                Try
                    Variable = CType(ValueTable.Item(ValueName), Integer)
                Catch ex As Exception
                End Try
            End If
        End Sub

        Private Shared Sub ReadValue(ByRef ValueTable As Hashtable, ByVal ValueName As String, ByRef Variable As Boolean)
            If Not ValueTable.Item(ValueName) Is Nothing Then
                Try
                    Variable = CType(ValueTable.Item(ValueName), Boolean)
                Catch ex As Exception
                End Try
            End If
        End Sub

        Private Shared Sub ReadValue(ByRef ValueTable As Hashtable, ByVal ValueName As String, ByRef Variable As System.Web.UI.WebControls.FirstDayOfWeek)
            If Not ValueTable.Item(ValueName) Is Nothing Then
                Try
                    Variable = CType(CInt(ValueTable.Item(ValueName)), System.Web.UI.WebControls.FirstDayOfWeek)
                Catch ex As Exception
                End Try
            End If
        End Sub

        Private Shared Sub ReadValue(ByRef ValueTable As Hashtable, ByVal ValueName As String, ByRef Variable As Double)
            If Not ValueTable.Item(ValueName) Is Nothing Then
                Try
                    Variable = CType(ValueTable.Item(ValueName), Double)
                Catch ex As Exception
                End Try
            End If
        End Sub

        Private Shared Sub ReadValue(ByRef ValueTable As Hashtable, ByVal ValueName As String, ByRef Variable As Single)
            If Not ValueTable.Item(ValueName) Is Nothing Then
                Try
                    Variable = CType(ValueTable.Item(ValueName), Single)
                Catch ex As Exception
                End Try
            End If
        End Sub

        Private Shared Sub ReadValue(ByRef ValueTable As Hashtable, ByVal ValueName As String, ByRef Variable As Telerik.Web.UI.ToolTipHideEvent)
            If Not ValueTable.Item(ValueName) Is Nothing Then
                Try
                    Variable = CType(ValueTable.Item(ValueName), Telerik.Web.UI.ToolTipHideEvent)
                Catch ex As Exception
                End Try
            End If
        End Sub

        Private Shared Sub ReadValue(ByRef ValueTable As Hashtable, ByVal ValueName As String, ByRef Variable As Telerik.Web.UI.ToolTipRelativeDisplay)
            If Not ValueTable.Item(ValueName) Is Nothing Then
                Try
                    Variable = CType(ValueTable.Item(ValueName), Telerik.Web.UI.ToolTipRelativeDisplay)
                Catch ex As Exception
                End Try
            End If
        End Sub

#End Region

    End Class

#End Region
End Namespace
